package com.tjtt.common.utils;

import java.util.HashMap;
import java.util.Map.Entry;
import org.apache.log4j.Logger;

import javax.xml.bind.annotation.adapters.XmlAdapter;

public class OtherValuesAdapter extends
		XmlAdapter<OtherValues[], HashMap<String, String>> {
	static Logger logger = Logger.getLogger(OtherValuesAdapter.class.getName());

	public HashMap<String, String> unmarshal(OtherValues[] value) {
		logger.error("unmarshal begin");
		HashMap<String, String> r = new HashMap<String, String>();
		for (OtherValues c : value)
			r.put(c.key, c.value);
		return r;
	}

	public OtherValues[] marshal(HashMap<String, String> value) {
		logger.error("marshal begin");
		OtherValues[] pairs = new OtherValues[value.size()];
		int i = 0;
		for (Entry<String, String> entry : value.entrySet()) {
			pairs[i++] = new OtherValues(entry.getKey(), entry.getValue());
		}
		return pairs;
	}
}
